package com.itheima.SdClass;

import java.util.Scanner;

//JavaBean类 : 封装数据
public class SdStudent {

    //成员变量全部私有 - 保护数据
    private String name;
    private int ID;
    private int age;

    //构造方法
    //无参构造
    public SdStudent(){}
    //含参构造
    public SdStudent(String name, int id, int age){
        this.name = name;
        this.ID = id;
        this.age = age;
    }

    //提供入口 - 访问私有数据
    //姓名
    public void setName(String name){
        this.name = name;
    }
    public String getName(){
        return this.name;
    }
    //学号
    public void setId(){
        Scanner sc = new Scanner(System.in);
        int id = sc.nextInt();
        System.out.println();
        if(id < 200000 || id > 202199){
            System.out.print("请重新输入ID:");
            setId();
        }else this.ID = id;

    }
    public int getID(){
        return this.ID;
    }
    //年龄
    public void setAge(){
        Scanner sc = new Scanner(System.in);
        int age = sc.nextInt();
        System.out.println();
        if(age > 0 && age < 130){
            this.age = age;
        }else {
            System.out.print("请重输年龄:");
            setAge();
        }
    }
    public int getAge(){
        return this.age;
    }
    //全部显示
    public void show() {
        System.out.println(this.name + "今年"+this.age+"岁,学号为"+this.ID);
    }

}
